// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: node_proxy.hpp 210 2008-08-28 10:10:41Z heavyzheng $
//

#ifndef ZZHENG_XML_DOM_NODE_PROXY_HPP_20080728__
#define ZZHENG_XML_DOM_NODE_PROXY_HPP_20080728__

#include <zzheng/xml/config.hpp>
#include <zzheng/xml/dom/types.hpp>
#include <string>

namespace zzheng {
namespace xml {
namespace dom {

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // attribute_proxy
    //

    //! The proxy class for XML attribute.
    class attribute_proxy {

    public:

        explicit attribute_proxy(const std::string& uri,
                                 const std::string& name,
                                 const std::string& value)
        : uri_(uri), name_(name), value_(value) {
            // Do nothing.
        }

        // Use auto-generated copy constructor.
        // Use auto-generated copy assignment.
        // Use auto-generated destructor.

        const std::string& uri() const {
            return uri_;
        }

        const std::string& name() const {
            return name_;
        }

        const std::string& value() const {
            return value_;
        }

        std::string str() const {
            return ( "attribute_proxy:" + name() + "=" + value() );
        }

    private:

        std::string uri_;
        std::string name_;
        std::string value_;

    }; // class attribute_proxy

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // element_proxy
    //

    //! The proxy class for XML element.
    class element_proxy {

    public:

        explicit element_proxy(const std::string& uri, const std::string& name)
        : uri_(uri), name_(name) {
            // Do nothing.
        }

        // Use auto-generated copy constructor.
        // Use auto-generated copy assignment.
        // Use auto-generated destructor.

        const std::string& uri() const {
            return uri_;
        }

        const std::string& name() const {
            return name_;
        }

        std::string str() const {
            return ( "element_proxy:" + name() );
        }

    private:

        std::string uri_;
        std::string name_;

    }; // class element_proxy

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // text_proxy
    //

    //! The proxy class for XML text or CData section.
    class text_proxy {

    public:

        explicit text_proxy(const std::string& value, bool cdata): value_(value), cdata_(cdata) {
            // Do nothing.
        }

        // Use auto-generated copy constructor.
        // Use auto-generated copy assignment.
        // Use auto-generated destructor.

        const std::string& value() const {
            return value_;
        }

        bool is_cdata() const {
            return cdata_;
        }

        std::string str() const {
            return ( "text_proxy" + (is_cdata() ? "(cdata)" : std::string()) + ":" + value() );
        }

    private:

        std::string value_;
        bool        cdata_;

    }; // class text_proxy

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // comment_proxy
    //

    //! The proxy class for XML comment.
    class comment_proxy {

    public:

        explicit comment_proxy(const std::string& value): value_(value) {
            // Do nothing.
        }

        // Use auto-generated copy constructor.
        // Use auto-generated copy assignment.
        // Use auto-generated destructor.

        const std::string& value() const {
            return value_;
        }

        std::string str() const {
            return ( "comment_proxy:" + value() );
        }

    private:

        std::string value_;

    }; // class comment_proxy

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // make_*
    //

    //! Makes an attribute proxy object.
    inline
    attribute_proxy make_attribute(const std::string& name,
                                   const std::string& value) {
        return attribute_proxy(std::string(), name, value);
    }

    //! Makes an attribute proxy object.
    inline
    attribute_proxy make_attribute(const std::string& uri,
                                   const std::string& name,
                                   const std::string& value) {
        return attribute_proxy(uri, name, value);
    }

    //! Makes an element proxy object.
    inline
    element_proxy make_element(const std::string& name) {
        return element_proxy(std::string(), name);
    }

    //! Makes an element proxy object.
    inline
    element_proxy make_element(const std::string& uri, const std::string& name) {
        return element_proxy(uri, name);
    }

    //! Makes a text proxy object.
    inline
    text_proxy make_text(const std::string& value) {
        return text_proxy(value, false);
    }

    //! Makes a CData section proxy object.
    inline
    text_proxy make_cdata(const std::string& value) {
        return text_proxy(value, true);
    }

    //! Makes a comment proxy object.
    inline
    comment_proxy make_comment(const std::string& value) {
        return comment_proxy(value);
    }

} // namespace zzheng::xml::dom
} // namespace zzheng::xml
} // namespace zzheng

#endif // ZZHENG_XML_DOM_NODE_PROXY_HPP_20080728__



